package com.example.qxfw.qxxx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.TownshipForecastProvince;
import com.example.qxfw.common.entity.qx.Weather;
import com.example.qxfw.qxxx.service.XzybService;
import com.example.qxfw.ybzz.service.ForecastInfoService;
import com.example.qxfw.ybzz.service.WeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

import static com.example.qxfw.common.util.StringUtil.toNull;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/8/10  星期四   9:17
 * @description : 乡镇预报
 ***************************************/
@Api(tags = "气象信息-乡镇预报")
@RestController
@CrossOrigin
@RequestMapping("/TownshipForecastController")
public class TownshipForecastController {

    @Autowired
    private XzybService xzybService;

    @Autowired
    private WeatherService weatherService;

    @Autowired
    private ForecastInfoService forecastInfoService;


    @ApiOperation("气象信息-乡镇预报-获取乡镇精细化预报")
    @GetMapping("/getTownshipForecast")
    public SysResult getTownshipForecast(String dateChar, String timeChar, Integer nTimes, String city) {
        System.out.println("预报时间 -> " + dateChar);
        System.out.println("预报时次 -> " + timeChar);
        System.out.println("预报时效 -> " + nTimes);
        System.out.println("预报城市 -> " + city);
        List<TownshipForecastProvince> list = xzybService.getList(dateChar, timeChar, nTimes, city);
        list.forEach(l->{
            l.setMaxtemp(toNull(l.getMaxtemp()));
            l.setMintemp(toNull(l.getMintemp()));
            l.setWinds(toNull(l.getWinds()));
            l.setWindd(toNull(l.getWindd()));
        });

        return SysResult.common(list.stream().distinct().collect(Collectors.toList()));
    }

    @ApiOperation("气象信息-乡镇预报-获取天气信息")
    @GetMapping("/getWeather")
    public SysResult getWeather() {
        List<Weather> weathers = weatherService.getWeather();
        return SysResult.success(weathers, weathers.size());
    }

    @ApiOperation("气象信息-乡镇预报-获取风力信息")
    @GetMapping("/getWind")
    public SysResult getWind() {
        List<Weather> weathers = weatherService.getWind();
        return SysResult.success(weathers, weathers.size());
    }

    @ApiOperation("气象信息-乡镇预报-获取天气 信息")
    @GetMapping("/getWindd")
    public SysResult getWindd() {
        List<Weather> weathers = weatherService.getWindd();
        return SysResult.success(weathers, weathers.size());
    }

    @ApiOperation("气象信息-乡镇预报-获取预报最新时间")
    @GetMapping("/getMaxTime")
    public SysResult getMaxTime() {
        List<TownshipForecastProvince> forecastInfos = xzybService.getMaxTime();
        return SysResult.success(forecastInfos);
    }


}
